package com.wugui.datax.admin.tool.meta;
/**
 * Cache数据库 meta信息查询
 *
 * @author zhouhongfa@gz-yibo.com
 * @ClassName CacheDatabaseMeta
 * @Version 1.0
 * @since 2023/8/13
 */
public class CacheDatabaseMeta extends BaseDatabaseMeta implements DatabaseInterface {

    private volatile static CacheDatabaseMeta single;

    public static CacheDatabaseMeta getInstance() {
        if (single == null) {
            synchronized (CacheDatabaseMeta.class) {
                if (single == null) {
                    single = new CacheDatabaseMeta();
                }
            }
        }
        return single;
    }
    /**
     * 查询注释
     * @param schemaName
     * @param tableName
     * @param columnName
     * @return
     */
    @Override
    public String getSQLQueryComment(String schemaName, String tableName, String columnName) {
        return String.format("select B.Description \n" +
                "  from %Dictionary.ClassDefinition A, %Dictionary.PropertyDefinition B\n" +
                " where a.id = b.parent\n" +
                "   and A.SqlTableName = '%s'\n" +
                "   AND B.SqlFieldName  = '%s'", tableName, columnName);
    }

    @Override
    public String getSQLQueryPrimaryKey() {
        return "select 'ID'";
    }

    @Override
    public String getSQLQueryTablesNameComments() {
        return "select SqlTableName,Description from %Dictionary.ClassDefinition";
    }

    @Override
    public String getSQLQueryTableNameComment() {
        return "select SqlTableName,Description from %Dictionary.ClassDefinition where SqlTableName = ?";
    }

    @Override
    public String getSQLQueryTables(String... tableSchema) {
        return "SELECT TABLE_SCHEMA||'.'|| TABLE_NAME FROM information_schema.tables where TABLE_SCHEMA='" + tableSchema[0] + "'";
    }

    @Override
    public String getSQLQueryTableSchema(String... args) {
        return "SELECT TABLE_SCHEMA FROM information_schema.tables";
    }


    @Override
    public String getSQLQueryTables() {
        return "SELECT TABLE_SCHEMA||'.'|| TABLE_NAME as TABLE_NAME FROM information_schema.tables where TABLE_TYPE='BASE TABLE'";
    }

    @Override
    public String getSQLQueryColumns(String... args) {
        return "SELECT TABLE_SCHEMA||'.'|| TABLE_NAME as TABLE_NAME FROM information_schema.tables where TABLE_TYPE='BASE TABLE'";
    }
}
